package demo.thread;

public class ThreadGroupTest {
    public static void main(String[] args) {
        // 创建一个线程组，并重新定义异常
        ThreadGroup group = new ThreadGroup("MyThreadGroup") {
            @Override
            public void uncaughtException(Thread thread, Throwable e) {
                System.out.println("******************************");
                System.out.println("当前线程组名称: " + thread.getThreadGroup().getName());
                System.out.println("线程 [" + thread.getName() + "] 抛出异常: " + e.getMessage());
                System.out.println("******************************");
            }
        };

        // 测试异常
        Thread thread = new Thread(group, new Runnable() {
            @Override
            public void run() {
                // 抛出异常
                throw new RuntimeException("测试异常");
            }
        }, "TestThread");

        // 启动线程
        thread.start();
    }
}
